home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / Bit / Vector.pm < prev   
Encoding:
Perl POD Document  |  1999-12-28  |  64.7 KB  |  2,346 lines

  1.  
  2.  
  3. package Bit::Vector;
  4.  
  5. use strict;
  6. use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION);
  7.  
  8. require Exporter;
  9. require DynaLoader;
  10.  
  11. @ISA = qw(Exporter DynaLoader);
  12.  
  13. @EXPORT = qw();
  14.  
  15. @EXPORT_OK = qw();
  16.  
  17. $VERSION = '4.2';
  18.  
  19. bootstrap Bit::Vector $VERSION;
  20.  
  21. use Carp;
  22.  
  23. use overload
  24.       '""' => '_string',
  25.      'neg' => '_complement',
  26.        '~' => '_complement',
  27.     'bool' => '_boolean',
  28.        '!' => '_not_boolean',
  29.      'abs' => '_norm',
  30.       '++' => '_increment',
  31.       '--' => '_decrement',
  32.        '+' => '_union',
  33.        '|' => '_union',                # alternative for '+'
  34.        '-' => '_difference',
  35.        '*' => '_intersection',
  36.        '&' => '_intersection',         # alternative for '*'
  37.        '^' => '_exclusive_or',
  38.       '<<' => '_move_left',
  39.       '>>' => '_move_right',
  40.       '+=' => '_assign_union',
  41.       '|=' => '_assign_union',         # alternative for '+='
  42.       '-=' => '_assign_difference',
  43.       '*=' => '_assign_intersection',
  44.       '&=' => '_assign_intersection',  # alternative for '*='
  45.       '^=' => '_assign_exclusive_or',
  46.      '<<=' => '_assign_move_left',
  47.      '>>=' => '_assign_move_right',
  48.       '==' => '_equal',
  49.       '!=' => '_not_equal',
  50.        '<' => '_true_sub_set',
  51.       '<=' => '_sub_set',
  52.        '>' => '_true_super_set',
  53.       '>=' => '_super_set',
  54.      'cmp' => '_compare',              # also enables lt, le, gt, ge, eq, ne
  55.        '=' => '_clone',
  56. 'fallback' =>   undef;
  57.  
  58. sub Shadow
  59. {
  60.     croak "Usage: \$other_vector = \$some_vector->Shadow();"
  61.       if (@_ != 1);
  62.  
  63.     my($object) = @_;
  64.     my($result);
  65.  
  66.     $result = $object->new($object->Size());
  67.     return($result);
  68. }
  69.  
  70. sub Clone
  71. {
  72.     croak "Usage: \$twin_vector = \$some_vector->Clone();"
  73.       if (@_ != 1);
  74.  
  75.     my($object) = @_;
  76.     my($result);
  77.  
  78.     $result = $object->new($object->Size());
  79.     $result->Copy($object);
  80.     return($result);
  81. }
  82.  
  83. sub to_ASCII
  84. {
  85.     croak "Usage: \$string = \$vector->to_ASCII();"
  86.       if (@_ != 1);
  87.  
  88.     my($object) = @_;
  89.     my($start,$string);
  90.     my($min,$max);
  91.  
  92.     $start = 0;
  93.     $string = '';
  94.     while (($start < $object->Size()) &&
  95.         (($min,$max) = $object->Interval_Scan_inc($start)))
  96.     {
  97.         $start = $max + 2;
  98.         if    ($min == $max)   { $string .= "${min},"; }
  99.         elsif ($min == $max-1) { $string .= "${min},${max},"; }
  100.         else                   { $string .= "${min}-${max},"; }
  101.     }
  102.     $string =~ s/,$//;
  103.     return($string);
  104. }
  105.  
  106. sub from_ASCII
  107. {
  108.     croak "Usage: \$vector->from_ASCII(\$string);"
  109.       if (@_ != 2);
  110.  
  111.     my($object,$string) = @_;
  112.     my(@intervals,$interval);
  113.     my($min,$max);
  114.  
  115.     croak "Bit::Vector::from_ASCII(): syntax error in input string"
  116.       unless ($string =~ /^ (?: \d+ (?: - \d+ )? )
  117.                       (?: , (?: \d+ (?: - \d+ )? ) )* $/x);
  118.  
  119.     $object->Empty();
  120.  
  121.     @intervals = split(/,/, $string);
  122.  
  123.     foreach $interval (@intervals)
  124.     {
  125.         if ($interval =~ /-/)
  126.         {
  127.             ($min,$max) = split(/-/, $interval);
  128.  
  129.             croak "Bit::Vector::from_ASCII(): minimum index out of range"
  130.               if (($min < 0) || ($min >= $object->Size()));
  131.  
  132.             croak "Bit::Vector::from_ASCII(): maximum index out of range"
  133.               if (($max < 0) || ($max >= $object->Size()));
  134.  
  135.             croak "Bit::Vector::from_ASCII(): minimum > maximum index"
  136.               if ($min > $max);
  137.  
  138.             $object->Interval_Fill($min,$max);
  139.         }
  140.         else
  141.         {
  142.             croak "Bit::Vector::from_ASCII(): index out of range"
  143.               if (($interval < 0) || ($interval >= $object->Size()));
  144.  
  145.             $object->Bit_On($interval);
  146.         }
  147.     }
  148. }
  149.  
  150. sub new_from_String
  151. {
  152.     croak "Usage: \$vector = Bit::Vector->new_from_String(\$string);"
  153.       if (@_ != 2);
  154.  
  155.     my $proto  = shift;
  156.     my $class  = ref($proto) || $proto || 'Bit::Vector';
  157.     my $string = shift;
  158.     my($length);
  159.     my($result);
  160.  
  161.     $length = length($string) * 4;
  162.  
  163.     if ($length > 0)
  164.     {
  165.         $result = Bit::Vector::new( $class, $length );
  166.  
  167.         if (defined($result) && ref($result) && (${$result} != 0))
  168.         {
  169.             if ($result->from_string($string))
  170.             {
  171.                 return($result);
  172.             }
  173.             else
  174.             {
  175.                 croak
  176. "Bit::Vector::new_from_String(): syntax error in input string";
  177.             }
  178.         }
  179.         else
  180.         {
  181.             croak
  182. "Bit::Vector::new_from_String(): unable to create new 'Bit::Vector' object";
  183.         }
  184.     }
  185.     else
  186.     {
  187.         croak
  188. "Bit::Vector::new_from_String(): zero length 'Bit::Vector' object not permitted";
  189.     }
  190. }
  191.  
  192. sub _string
  193. {
  194.     my($object,$argument,$flag) = @_;
  195.  
  196.     return( $object->to_ASCII() );
  197. }
  198.  
  199. sub _complement
  200. {
  201.     my($object,$argument,$flag) = @_;
  202.     my($result);
  203.  
  204.     $result = $object->new($object->Size());
  205.     $result->Complement($object);
  206.     return($result);
  207. }
  208.  
  209. sub _boolean
  210. {
  211.     my($object,$argument,$flag) = @_;
  212.  
  213.     return( ! $object->is_empty() );
  214. }
  215.  
  216. sub _not_boolean
  217. {
  218.     my($object,$argument,$flag) = @_;
  219.  
  220.     return( $object->is_empty() );
  221. }
  222.  
  223. sub _norm
  224. {
  225.     my($object,$argument,$flag) = @_;
  226.  
  227.     return( $object->Norm() );
  228. }
  229.  
  230. sub _increment
  231. {
  232.     my($object,$argument,$flag) = @_;
  233.  
  234.     return( $object->increment() );
  235. }
  236.  
  237. sub _decrement
  238. {
  239.     my($object,$argument,$flag) = @_;
  240.  
  241.     return( $object->decrement() );
  242. }
  243.  
  244. sub _union
  245. {
  246.     my($object,$argument,$flag) = @_;
  247.     my($name) = "'+'"; #&_trace($name,$object,$argument,$flag);
  248.     my($result);
  249.  
  250.     if ((defined $argument) && ref($argument) &&
  251.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  252.     {
  253.         if (defined $flag)
  254.         {
  255.             $result = $object->new($object->Size());
  256.             $result->Union($object,$argument);
  257.             return($result);
  258.         }
  259.         else
  260.         {
  261.             $object->Union($object,$argument);
  262.             return($object);
  263.         }
  264.     }
  265.     elsif ((defined $argument) && !(ref($argument)))
  266.     {
  267.         if (defined $flag)
  268.         {
  269.             $result = $object->new($object->Size());
  270.             $result->Copy($object);
  271.             $result->Bit_On($argument);
  272.             return($result);
  273.         }
  274.         else
  275.         {
  276.             $object->Bit_On($argument);
  277.             return($object);
  278.         }
  279.     }
  280.     else
  281.     {
  282.         croak "Bit::Vector $name: wrong argument type";
  283.     }
  284. }
  285.  
  286. sub _difference
  287. {
  288.     my($object,$argument,$flag) = @_;
  289.     my($name) = "'-'"; #&_trace($name,$object,$argument,$flag);
  290.     my($result);
  291.  
  292.     if ((defined $argument) && ref($argument) &&
  293.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  294.     {
  295.         if (defined $flag)
  296.         {
  297.             $result = $object->new($object->Size());
  298.             if ($flag) { $result->Difference($argument,$object); }
  299.             else       { $result->Difference($object,$argument); }
  300.             return($result);
  301.         }
  302.         else
  303.         {
  304.             $object->Difference($object,$argument);
  305.             return($object);
  306.         }
  307.     }
  308.     elsif ((defined $argument) && !(ref($argument)))
  309.     {
  310.         if (defined $flag)
  311.         {
  312.             $result = $object->new($object->Size());
  313.             if ($flag)
  314.             {
  315.                 unless ($object->bit_test($argument))
  316.                 { $result->Bit_On($argument); }
  317.             }
  318.             else
  319.             {
  320.                 $result->Copy($object);
  321.                 $result->Bit_Off($argument);
  322.             }
  323.             return($result);
  324.         }
  325.         else
  326.         {
  327.             $object->Bit_Off($argument);
  328.             return($object);
  329.         }
  330.     }
  331.     else
  332.     {
  333.         croak "Bit::Vector $name: wrong argument type";
  334.     }
  335. }
  336.  
  337. sub _intersection
  338. {
  339.     my($object,$argument,$flag) = @_;
  340.     my($name) = "'*'"; #&_trace($name,$object,$argument,$flag);
  341.     my($result);
  342.  
  343.     if ((defined $argument) && ref($argument) &&
  344.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  345.     {
  346.         if (defined $flag)
  347.         {
  348.             $result = $object->new($object->Size());
  349.             $result->Intersection($object,$argument);
  350.             return($result);
  351.         }
  352.         else
  353.         {
  354.             $object->Intersection($object,$argument);
  355.             return($object);
  356.         }
  357.     }
  358.     elsif ((defined $argument) && !(ref($argument)))
  359.     {
  360.         if (defined $flag)
  361.         {
  362.             $result = $object->new($object->Size());
  363.             if ($object->bit_test($argument))
  364.             { $result->Bit_On($argument); }
  365.             return($result);
  366.         }
  367.         else
  368.         {
  369.             $flag = $object->bit_test($argument);
  370.             $object->Empty();
  371.             if ($flag) { $object->Bit_On($argument); }
  372.             return($object);
  373.         }
  374.     }
  375.     else
  376.     {
  377.         croak "Bit::Vector $name: wrong argument type";
  378.     }
  379. }
  380.  
  381. sub _exclusive_or
  382. {
  383.     my($object,$argument,$flag) = @_;
  384.     my($name) = "'^'"; #&_trace($name,$object,$argument,$flag);
  385.     my($result);
  386.  
  387.     if ((defined $argument) && ref($argument) &&
  388.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  389.     {
  390.         if (defined $flag)
  391.         {
  392.             $result = $object->new($object->Size());
  393.             $result->ExclusiveOr($object,$argument);
  394.             return($result);
  395.         }
  396.         else
  397.         {
  398.             $object->ExclusiveOr($object,$argument);
  399.             return($object);
  400.         }
  401.     }
  402.     elsif ((defined $argument) && !(ref($argument)))
  403.     {
  404.         if (defined $flag)
  405.         {
  406.             $result = $object->new($object->Size());
  407.             $result->Copy($object);
  408.             $result->bit_flip($argument);
  409.             return($result);
  410.         }
  411.         else
  412.         {
  413.             $object->bit_flip($argument);
  414.             return($object);
  415.         }
  416.     }
  417.     else
  418.     {
  419.         croak "Bit::Vector $name: wrong argument type";
  420.     }
  421. }
  422.  
  423. sub _move_left
  424. {
  425.     my($object,$argument,$flag) = @_;
  426.     my($name) = "'<<'"; #&_trace($name,$object,$argument,$flag);
  427.     my($result);
  428.  
  429.     if ((defined $argument) && !(ref($argument)))
  430.     {
  431.         if (defined $flag)
  432.         {
  433.             unless ($flag)
  434.             {
  435.                 $result = $object->new($object->Size());
  436.                 $result->Copy($object);
  437.                 $result->Move_Left($argument);
  438.                 return($result);
  439.             }
  440.             else
  441.             {
  442.                 croak "Bit::Vector $name: wrong argument type";
  443.             }
  444.         }
  445.         else
  446.         {
  447.             $object->Move_Left($argument);
  448.             return($object);
  449.         }
  450.     }
  451.     else
  452.     {
  453.         croak "Bit::Vector $name: wrong argument type";
  454.     }
  455. }
  456.  
  457. sub _move_right
  458. {
  459.     my($object,$argument,$flag) = @_;
  460.     my($name) = "'>>'"; #&_trace($name,$object,$argument,$flag);
  461.     my($result);
  462.  
  463.     if ((defined $argument) && !(ref($argument)))
  464.     {
  465.         if (defined $flag)
  466.         {
  467.             unless ($flag)
  468.             {
  469.                 $result = $object->new($object->Size());
  470.                 $result->Copy($object);
  471.                 $result->Move_Right($argument);
  472.                 return($result);
  473.             }
  474.             else
  475.             {
  476.                 croak "Bit::Vector $name: wrong argument type";
  477.             }
  478.         }
  479.         else
  480.         {
  481.             $object->Move_Right($argument);
  482.             return($object);
  483.         }
  484.     }
  485.     else
  486.     {
  487.         croak "Bit::Vector $name: wrong argument type";
  488.     }
  489. }
  490.  
  491. sub _assign_union
  492. {
  493.     my($object,$argument,$flag) = @_;
  494.  
  495.     return( &_union($object,$argument,undef) );
  496. }
  497.  
  498. sub _assign_difference
  499. {
  500.     my($object,$argument,$flag) = @_;
  501.  
  502.     return( &_difference($object,$argument,undef) );
  503. }
  504.  
  505. sub _assign_intersection
  506. {
  507.     my($object,$argument,$flag) = @_;
  508.  
  509.     return( &_intersection($object,$argument,undef) );
  510. }
  511.  
  512. sub _assign_exclusive_or
  513. {
  514.     my($object,$argument,$flag) = @_;
  515.  
  516.     return( &_exclusive_or($object,$argument,undef) );
  517. }
  518.  
  519. sub _assign_move_left
  520. {
  521.     my($object,$argument,$flag) = @_;
  522.  
  523.     return( &_move_left($object,$argument,undef) );
  524. }
  525.  
  526. sub _assign_move_right
  527. {
  528.     my($object,$argument,$flag) = @_;
  529.  
  530.     return( &_move_right($object,$argument,undef) );
  531. }
  532.  
  533. sub _equal
  534. {
  535.     my($object,$argument,$flag) = @_;
  536.     my($name) = "'=='"; #&_trace($name,$object,$argument,$flag);
  537.     my($result);
  538.  
  539.     if ((defined $argument) && ref($argument) &&
  540.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  541.     {
  542.         $result = $argument;
  543.     }
  544.     elsif ((defined $argument) && !(ref($argument)))
  545.     {
  546.         $result = $object->new($object->Size());
  547.         $result->Bit_On($argument);
  548.     }
  549.     else
  550.     {
  551.         croak "Bit::Vector $name: wrong argument type";
  552.     }
  553.     return( $object->equal($result) );
  554. }
  555.  
  556. sub _not_equal
  557. {
  558.     my($object,$argument,$flag) = @_;
  559.     my($name) = "'!='"; #&_trace($name,$object,$argument,$flag);
  560.     my($result);
  561.  
  562.     if ((defined $argument) && ref($argument) &&
  563.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  564.     {
  565.         $result = $argument;
  566.     }
  567.     elsif ((defined $argument) && !(ref($argument)))
  568.     {
  569.         $result = $object->new($object->Size());
  570.         $result->Bit_On($argument);
  571.     }
  572.     else
  573.     {
  574.         croak "Bit::Vector $name: wrong argument type";
  575.     }
  576.     return( !($object->equal($result)) );
  577. }
  578.  
  579. sub _true_sub_set
  580. {
  581.     my($object,$argument,$flag) = @_;
  582.     my($name) = "'<'"; #&_trace($name,$object,$argument,$flag);
  583.     my($result);
  584.  
  585.     if ((defined $argument) && ref($argument) &&
  586.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  587.     {
  588.         $result = $argument;
  589.     }
  590.     elsif ((defined $argument) && !(ref($argument)))
  591.     {
  592.         $result = $object->new($object->Size());
  593.         $result->Bit_On($argument);
  594.     }
  595.     else
  596.     {
  597.         croak "Bit::Vector $name: wrong argument type";
  598.     }
  599.     if ((defined $flag) && $flag)
  600.     {
  601.         return( !($result->equal($object)) &&
  602.                  ($result->subset($object)) );
  603.     }
  604.     else
  605.     {
  606.         return( !($object->equal($result)) &&
  607.                  ($object->subset($result)) );
  608.     }
  609. }
  610.  
  611. sub _sub_set
  612. {
  613.     my($object,$argument,$flag) = @_;
  614.     my($name) = "'<='"; #&_trace($name,$object,$argument,$flag);
  615.     my($result);
  616.  
  617.     if ((defined $argument) && ref($argument) &&
  618.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  619.     {
  620.         $result = $argument;
  621.     }
  622.     elsif ((defined $argument) && !(ref($argument)))
  623.     {
  624.         $result = $object->new($object->Size());
  625.         $result->Bit_On($argument);
  626.     }
  627.     else
  628.     {
  629.         croak "Bit::Vector $name: wrong argument type";
  630.     }
  631.     if ((defined $flag) && $flag)
  632.     {
  633.         return( $result->subset($object) );
  634.     }
  635.     else
  636.     {
  637.         return( $object->subset($result) );
  638.     }
  639. }
  640.  
  641. sub _true_super_set
  642. {
  643.     my($object,$argument,$flag) = @_;
  644.     my($name) = "'>'"; #&_trace($name,$object,$argument,$flag);
  645.     my($result);
  646.  
  647.     if ((defined $argument) && ref($argument) &&
  648.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  649.     {
  650.         $result = $argument;
  651.     }
  652.     elsif ((defined $argument) && !(ref($argument)))
  653.     {
  654.         $result = $object->new($object->Size());
  655.         $result->Bit_On($argument);
  656.     }
  657.     else
  658.     {
  659.         croak "Bit::Vector $name: wrong argument type";
  660.     }
  661.     if ((defined $flag) && $flag)
  662.     {
  663.         return( !($object->equal($result)) &&
  664.                  ($object->subset($result)) );
  665.     }
  666.     else
  667.     {
  668.         return( !($result->equal($object)) &&
  669.                  ($result->subset($object)) );
  670.     }
  671. }
  672.  
  673. sub _super_set
  674. {
  675.     my($object,$argument,$flag) = @_;
  676.     my($name) = "'>='"; #&_trace($name,$object,$argument,$flag);
  677.     my($result);
  678.  
  679.     if ((defined $argument) && ref($argument) &&
  680.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  681.     {
  682.         $result = $argument;
  683.     }
  684.     elsif ((defined $argument) && !(ref($argument)))
  685.     {
  686.         $result = $object->new($object->Size());
  687.         $result->Bit_On($argument);
  688.     }
  689.     else
  690.     {
  691.         croak "Bit::Vector $name: wrong argument type";
  692.     }
  693.     if ((defined $flag) && $flag)
  694.     {
  695.         return( $object->subset($result) );
  696.     }
  697.     else
  698.     {
  699.         return( $result->subset($object) );
  700.     }
  701. }
  702.  
  703. sub _compare
  704. {
  705.     my($object,$argument,$flag) = @_;
  706.     my($name) = "cmp"; #&_trace($name,$object,$argument,$flag);
  707.     my($result);
  708.  
  709.     if ((defined $argument) && ref($argument) &&
  710.         (ref($argument) !~ /^SCALAR$|^ARRAY$|^HASH$|^CODE$|^REF$/))
  711.     {
  712.         $result = $argument;
  713.     }
  714.     elsif ((defined $argument) && !(ref($argument)))
  715.     {
  716.         $result = $object->new($object->Size());
  717.         $result->Bit_On($argument);
  718.     }
  719.     else
  720.     {
  721.         croak "Bit::Vector $name: wrong argument type";
  722.     }
  723.     if ((defined $flag) && $flag)
  724.     {
  725.         return( $result->Compare($object) );
  726.     }
  727.     else
  728.     {
  729.         return( $object->Compare($result) );
  730.     }
  731. }
  732.  
  733. sub _clone
  734. {
  735.     my($object,$argument,$flag) = @_;
  736.     my($result);
  737.  
  738.     $result = $object->new($object->Size());
  739.     $result->Copy($object);
  740.     return($result);
  741. }
  742.  
  743. sub _trace
  744. {
  745.     my($text,$object,$argument,$flag) = @_;
  746.  
  747.     unless (defined $object)   { $object   = 'undef'; };
  748.     unless (defined $argument) { $argument = 'undef'; };
  749.     unless (defined $flag)     { $flag     = 'undef'; };
  750.     if (ref($object))   { $object   = ref($object);   }
  751.     if (ref($argument)) { $argument = ref($argument); }
  752.     print "$text: \$obj='$object' \$arg='$argument' \$flag='$flag'\n";
  753. }
  754.  
  755. 1;
  756.  
  757. __END__
  758.  
  759. =head1 NAME
  760.  
  761. Bit::Vector - bit vectors of arbitrary length (base class)
  762.  
  763. Versatile implementation of bit vectors of arbitrary length
  764. with efficient and easy-to-use methods for various applications,
  765. especially sets.
  766.  
  767. Base class for all applications and classes using bit vectors as
  768. their underlying data type.
  769.  
  770. Provides overloaded arithmetic and relational operators for maximum
  771. comfort.
  772.  
  773. For an analysis of the time complexity of the methods implemented in
  774. this module, please refer to the file "COMPLEXITY" in the "Bit::Vector"
  775. distribution directory!
  776.  
  777. =head1 SYNOPSIS
  778.  
  779. =head2 METHODS IMPLEMENTED IN C (fastest)
  780.  
  781.   Version
  782.       $version = Bit::Vector::Version(); # version of "Vector.xs"
  783.  
  784.   new
  785.       $vector = new Bit::Vector($elements);
  786.       $vector = Bit::Vector->new($elements);
  787.       $vector = $any_vector->new($elements);
  788.  
  789.   Resize
  790.       $vector->Resize($elements);
  791.  
  792.   Size
  793.       $elements = $vector->Size();
  794.  
  795.   Empty
  796.       $vector->Empty();
  797.  
  798.   Fill
  799.       $vector->Fill();
  800.  
  801.   Flip
  802.       $vector->Flip();
  803.  
  804.   Interval_Empty
  805.       $vector->Interval_Empty($min,$max);
  806.  
  807.   Interval_Fill
  808.       $vector->Interval_Fill($min,$max);
  809.  
  810.   Interval_Flip
  811.       $vector->Interval_Flip($min,$max);
  812.  
  813.   Interval_Scan_inc
  814.       while (($min,$max) = $vector->Interval_Scan_inc($start))
  815.  
  816.   Interval_Scan_dec
  817.       while (($min,$max) = $vector->Interval_Scan_dec($start))
  818.  
  819.   Bit_Off
  820.       $vector->Bit_Off($index);
  821.       $vector->Delete($index);           # (deprecated)
  822.  
  823.   Bit_On
  824.       $vector->Bit_On($index);
  825.       $vector->Insert($index);           # (deprecated)
  826.  
  827.   bit_flip
  828.       $bit = $vector->bit_flip($index);
  829.       if ($vector->bit_flip($index))
  830.       $bit = $vector->flip($index);      # (deprecated)
  831.       if ($vector->flip($index))         # (deprecated)
  832.  
  833.   bit_test
  834.       $bit = $vector->bit_test($index);
  835.       if ($vector->bit_test($index))
  836.       $bit = $vector->contains($index);
  837.       if ($vector->contains($index))
  838.       $bit = $vector->in($index);        # (deprecated)
  839.       if ($vector->in($index))           # (deprecated)
  840.  
  841.   is_empty
  842.       if ($vector->is_empty())
  843.  
  844.   is_full
  845.       if ($vector->is_full())
  846.  
  847.   equal
  848.       if ($vector1->equal($vector2))
  849.  
  850.   lexorder
  851.       if ($vector1->lexorder($vector2))
  852.  
  853.   Compare
  854.       $cmp = $vector1->Compare($vector2);
  855.  
  856.   Copy
  857.       $vector1->Copy($vector2);
  858.  
  859.   rotate_left
  860.       $carry_out = $vector->rotate_left();
  861.  
  862.   rotate_right
  863.       $carry_out = $vector->rotate_right();
  864.  
  865.   shift_left
  866.       $carry_out = $vector->shift_left($carry_in);
  867.  
  868.   shift_right
  869.       $carry_out = $vector->shift_right($carry_in);
  870.  
  871.   Move_Left
  872.       $vector->Move_Left($bits);
  873.  
  874.   Move_Right
  875.       $vector->Move_Right($bits);
  876.  
  877.   increment
  878.       $carry = $vector->increment();
  879.  
  880.   decrement
  881.       $carry = $vector->decrement();
  882.  
  883.   to_String
  884.       $string = $vector->to_String();    # e.g., "A08A28AC"
  885.  
  886.   from_string
  887.       $ok = $vector->from_string($string);
  888.  
  889.   Union
  890.       $set1->Union($set2,$set3);         # in-place is possible!
  891.  
  892.   Intersection
  893.       $set1->Intersection($set2,$set3);  # in-place is possible!
  894.  
  895.   Difference
  896.       $set1->Difference($set2,$set3);    # in-place is possible!
  897.  
  898.   ExclusiveOr
  899.       $set1->ExclusiveOr($set2,$set3);   # in-place is possible!
  900.  
  901.   Complement
  902.       $set1->Complement($set2);          # in-place is possible!
  903.  
  904.   subset
  905.       if ($set1->subset($set2))
  906.       if ($set1->inclusion($set2))       # (deprecated)
  907.  
  908.   Norm
  909.       $norm = $set->Norm();
  910.  
  911.   Min
  912.       $min = $set->Min();
  913.  
  914.   Max
  915.       $max = $set->Max();
  916.  
  917.   Multiplication
  918.       $matrix1->Multiplication($rows1,$cols1,
  919.       $matrix2,$rows2,$cols2,
  920.       $matrix3,$rows3,$cols3);
  921.  
  922.   Closure
  923.       $matrix->Closure($rows,$cols);
  924.  
  925. =head2 METHODS IMPLEMENTED IN PERL
  926.  
  927.   Version
  928.       $version = $Bit::Vector::VERSION;  # version of "Vector.pm"
  929.  
  930.   Shadow
  931.       $other_vector = $some_vector->Shadow();
  932.  
  933.   Clone
  934.       $twin_vector = $some_vector->Clone();
  935.  
  936.   new_from_String
  937.       eval { $vector = Bit::Vector->new_from_String($string); };
  938.  
  939.   to_ASCII
  940.       $string = $vector->to_ASCII();     # e.g., "2,3,5-7,11,13-19"
  941.  
  942.   from_ASCII
  943.       eval { $vector->from_ASCII($string); };
  944.  
  945. =head2 OVERLOADED OPERATORS (slowest)
  946.  
  947.  
  948.   Emptyness
  949.       if ($vector) # if not empty
  950.       if (! $vector) # if empty
  951.       unless ($vector) # if empty
  952.  
  953.   Equality
  954.       if ($vector1 == $vector2)
  955.       if ($vector1 != $vector2)
  956.       if ($vector == $index)
  957.       if ($vector != $index)
  958.  
  959.   Lexical Comparison
  960.       $cmp = $vector1 cmp $vector2;
  961.       if ($vector1 lt $vector2)
  962.       if ($vector1 le $vector2)
  963.       if ($vector1 gt $vector2)
  964.       if ($vector1 ge $vector2)
  965.       if ($vector1 eq $vector2)
  966.       if ($vector1 ne $vector2)
  967.       $cmp = $vector cmp $index;
  968.       if ($vector lt $index)
  969.       if ($vector le $index)
  970.       if ($vector gt $index)
  971.       if ($vector ge $index)
  972.       if ($vector eq $index)
  973.       if ($vector ne $index)
  974.  
  975.   Move Left
  976.       $vector1 = $vector2 << $bits;
  977.       $vector <<= $bits;
  978.  
  979.   Move Right
  980.       $vector1 = $vector2 >> $bits;
  981.       $vector >>= $bits;
  982.  
  983.   Increment
  984.       ++$vector;
  985.       $vector++;
  986.  
  987.   Decrement
  988.       --$vector;
  989.       $vector--;
  990.  
  991.   String Conversion
  992.       $string = "$vector";
  993.       print "\$vector = '$vector'\n";
  994.  
  995.   Union
  996.       $set1 = $set2 + $set3;
  997.       $set1 += $set2;
  998.       $set1 = $set2 | $set3;
  999.       $set1 |= $set2;
  1000.       $vector1 = $vector2 + $index;
  1001.       $vector += $index;
  1002.       $vector1 = $vector2 | $index;
  1003.       $vector |= $index;
  1004.  
  1005.   Intersection
  1006.       $set1 = $set2 * $set3;
  1007.       $set1 *= $set2;
  1008.       $set1 = $set2 & $set3;
  1009.       $set1 &= $set2;
  1010.       $vector1 = $vector2 * $index;
  1011.       $vector *= $index;
  1012.       $vector1 = $vector2 & $index;
  1013.       $vector &= $index;
  1014.  
  1015.   Difference
  1016.       $set1 = $set2 - $set3;
  1017.       $set1 -= $set2;
  1018.       $set1 = $set2 - $set1;
  1019.       $vector1 = $vector2 - $index;
  1020.       $vector1 = $index - $vector2;
  1021.       $vector -= $index;
  1022.  
  1023.   ExclusiveOr
  1024.       $set1 = $set2 ^ $set3;
  1025.       $set1 ^= $set2;
  1026.       $vector1 = $vector2 ^ $index;
  1027.       $vector ^= $index;
  1028.  
  1029.   Complement
  1030.       $set1 = -$set2;
  1031.       $set1 = ~$set2;
  1032.       $set = -$set;
  1033.       $set = ~$set;
  1034.  
  1035.   Subset Relationship
  1036.       if ($set1 <= $set2)
  1037.  
  1038.   True Subset Relationship
  1039.       if ($set1 < $set2)
  1040.  
  1041.   Superset Relationship
  1042.       if ($set1 >= $set2)
  1043.  
  1044.   True Superset Relationship
  1045.       if ($set1 > $set2)
  1046.  
  1047.   Norm
  1048.       $norm = abs($set);
  1049.  
  1050. =head1 IMPORTANT NOTES
  1051.  
  1052. =head2 GENERAL HINTS
  1053.  
  1054. =over 2
  1055.  
  1056. =item *
  1057.  
  1058. Method naming convention
  1059.  
  1060. Method names completely in lower case indicate a boolean return value!
  1061.  
  1062. (Except for method "C<new()>", of course.)
  1063.  
  1064. =item *
  1065.  
  1066. Boolean return values
  1067.  
  1068. Boolean return values in this class are always a numerical (!)
  1069. zero ("0") for "false" and a numerical (!) one ("1") for "true".
  1070.  
  1071. This means that you can use the methods of this class with boolean
  1072. return values as the conditional expression in "if", "unless" and
  1073. "while" statements.
  1074.  
  1075. =item *
  1076.  
  1077. Version
  1078.  
  1079. The function "C<Bit::Vector::Version()>" (the version of the "Vector.xs"
  1080. file) should always return the same version number as contained in the
  1081. variable "C<$Bit::Vector::VERSION>" (the version of the "Vector.pm" file).
  1082.  
  1083. =back
  1084.  
  1085. =head2 METHODS IMPLEMENTED IN C
  1086.  
  1087. =over 2
  1088.  
  1089. =item *
  1090.  
  1091. C<$vector = Bit::Vector-E<gt>new($elements);>
  1092.  
  1093. This is the bit vector constructor method.
  1094.  
  1095. Call this method to create a new bit vector containing
  1096. "$elements" bits (with indices from C<0> to C<$elements - 1>).
  1097.  
  1098. The method returns a reference to the new bit vector.
  1099.  
  1100. A new bit vector is always initialized so that all bits are cleared
  1101. (turned off).
  1102.  
  1103. An exception will be raised if the method is unable to allocate the
  1104. necessary memory.
  1105.  
  1106. An exception will also be raised if you try to create a bit vector
  1107. with zero elements (i.e., with length zero).
  1108.  
  1109. Note that if you specify a negative number for "$elements" it
  1110. will be interpreted as a large positive number due to its internal
  1111. 2's complement binary representation!
  1112.  
  1113. In such a case, the bit vector constructor method will obediently attempt
  1114. to create a bit vector of that size, probably resulting in an exception,
  1115. as explained above.
  1116.  
  1117. =item *
  1118.  
  1119. C<$vector-E<gt>Resize($elements);>
  1120.  
  1121. Changes the size of the given vector to the specified number of bits.
  1122.  
  1123. This method allows you to change the size of an existing bit vector or
  1124. set, preserving as many bits from the old vector as will fit into the
  1125. new one (i.e., all bits with indices smaller than the minimum of the
  1126. sizes of the two vectors, old and new).
  1127.  
  1128. If the number of machine words needed to store the new vector is smaller
  1129. than or equal to the number of words needed to store the old vector, the
  1130. memory allocated for the old vector is reused for the new one, and only
  1131. the relevant book-keeping information is adjusted accordingly.
  1132.  
  1133. This means that even if the number of bits increases, new memory is not
  1134. necessarily being allocated (i.e., if the old and the new number of bits
  1135. fit into the same number of machine words)!
  1136.  
  1137. If the number of machine words needed to store the new vector is greater
  1138. than the number of words needed to store the old vector, new memory is
  1139. allocated for the new vector, the old vector is copied to the new one,
  1140. the remaining bits in the new vector are cleared (turned off) and the old
  1141. vector is deleted, i.e., the memory that was allocated for it is released.
  1142.  
  1143. This also means that if you decrease the size of a given vector so that
  1144. it will use fewer machine words, and increase it again later so that it
  1145. will use more words than before but still less than the original vector,
  1146. new memory will be allocated anyway because the information about the
  1147. size of the original vector is lost when you downsize it.
  1148.  
  1149. Note also that if you specify a negative number for "$elements" it
  1150. will be interpreted as a large positive number due to its internal
  1151. 2's complement binary representation!
  1152.  
  1153. In such a case, "Resize()" will obediently attempt to create a bit
  1154. vector of that size, probably resulting in an exception, as explained
  1155. above (see method "new()").
  1156.  
  1157. Finally, note that resizing a bit vector to a size of zero elements (length
  1158. zero) is disallowed; an exception will be raised if you try to do so.
  1159.  
  1160. =item *
  1161.  
  1162. C<$elements = $vector-E<gt>Size();>
  1163.  
  1164. Returns the size (number of bits) the given vector was created with
  1165. (or "C<Resize()>"d to).
  1166.  
  1167. =item *
  1168.  
  1169. C<$vector-E<gt>Empty();>
  1170.  
  1171. Clears all bits in the given vector.
  1172.  
  1173. =item *
  1174.  
  1175. C<$vector-E<gt>Fill();>
  1176.  
  1177. Sets all bits in the given vector.
  1178.  
  1179. =item *
  1180.  
  1181. C<$vector-E<gt>Flip();>
  1182.  
  1183. Flips (i.e., complements) all bits in the given vector.
  1184.  
  1185. =item *
  1186.  
  1187. C<$vector-E<gt>Interval_Empty($min,$max);>
  1188.  
  1189. Clears all bits in the interval C<[$min..$max]> (including both limits)
  1190. in the given vector.
  1191.  
  1192. "C<$min>" and "C<$max>" may have the same value; this is the same
  1193. as clearing a single bit with "C<Bit_Off()>" (but less efficient).
  1194.  
  1195. Note that C<$vector-E<gt>Interval_Empty(0,$vector-E<gt>Size()-1);>
  1196. is the same as C<$vector-E<gt>Empty();> (but less efficient).
  1197.  
  1198. =item *
  1199.  
  1200. C<$vector-E<gt>Interval_Fill($min,$max);>
  1201.  
  1202. Sets all bits in the interval C<[$min..$max]> (including both limits)
  1203. in the given vector.
  1204.  
  1205. "C<$min>" and "C<$max>" may have the same value; this is the same
  1206. as setting a single bit with "C<Bit_On()>" (but less efficient).
  1207.  
  1208. Note that C<$vector-E<gt>Interval_Fill(0,$vector-E<gt>Size()-1);>
  1209. is the same as C<$vector-E<gt>Fill();> (but less efficient).
  1210.  
  1211. =item *
  1212.  
  1213. C<$vector-E<gt>Interval_Flip($min,$max);>
  1214.  
  1215. Flips (i.e., complements) all bits in the interval C<[$min..$max]>
  1216. (including both limits) in the given vector.
  1217.  
  1218. "C<$min>" and "C<$max>" may have the same value; this is the same
  1219. as flipping a single bit with "C<bit_flip()>" (but less efficient).
  1220.  
  1221. Note that C<$vector-E<gt>Interval_Flip(0,$vector-E<gt>Size()-1);>
  1222. is the same as C<$vector-E<gt>Flip();> and
  1223. C<$vector-E<gt>Complement($vector);>
  1224. (but less efficient).
  1225.  
  1226. =item *
  1227.  
  1228. C<($min,$max) = $vector-E<gt>Interval_Scan_inc($start)>
  1229.  
  1230. Returns the minimum and maximum indices of the next contiguous block
  1231. of set bits (i.e., bits in the "on" state).
  1232.  
  1233. The search starts at index "$start" (i.e., C<"$min" E<gt>= "$start">)
  1234. and proceeds upwards (i.e., C<"$max" E<gt>= "$min">), thus repeatedly
  1235. increments the search pointer "$start" (internally).
  1236.  
  1237. Note though that the contents of the variable (or scalar literal value)
  1238. "$start" is not altered! I.e., you have to set it to the desired value
  1239. yourself prior to each call to "Interval_Scan_inc()"! (See also the
  1240. example given below!)
  1241.  
  1242. Actually, the bit vector is not searched bit by bit, but one machine
  1243. word at a time, in order to speed up execution (this means that this
  1244. method is quite efficient!).
  1245.  
  1246. An empty list is returned if no such block can be found.
  1247.  
  1248. Note that a single set bit (surrounded by cleared bits) is a valid
  1249. block by this definition. In that case the return values for "$min"
  1250. and "$max" are the same.
  1251.  
  1252. Typical use:
  1253.  
  1254.     $start = 0;
  1255.     while (($start < $vector->Size()) &&
  1256.         (($min,$max) = $vector->Interval_Scan_inc($start)))
  1257.     {
  1258.         $start = $max + 2;
  1259.  
  1260.     }
  1261.  
  1262. =item *
  1263.  
  1264. C<($min,$max) = $vector-E<gt>Interval_Scan_dec($start)>
  1265.  
  1266. Returns the minimum and maximum indices of the next contiguous block
  1267. of set bits (i.e., bits in the "on" state).
  1268.  
  1269. The search starts at index "$start" (i.e., C<"$max" E<lt>= "$start">)
  1270. and proceeds downwards (i.e., C<"$min" E<lt>= "$max">), thus repeatedly
  1271. decrements the search pointer "$start" (internally).
  1272.  
  1273. Note though that the contents of the variable (or scalar literal value)
  1274. "$start" is not altered! I.e., you have to set it to the desired value
  1275. yourself prior to each call to "Interval_Scan_dec()"! (See also the
  1276. example given below!)
  1277.  
  1278. Actually, the bit vector is not searched bit by bit, but one machine
  1279. word at a time, in order to speed up execution (this means that this
  1280. method is quite efficient!).
  1281.  
  1282. An empty list is returned if no such block can be found.
  1283.  
  1284. Note that a single set bit (surrounded by cleared bits) is a valid
  1285. block by this definition. In that case the return values for "$min"
  1286. and "$max" are the same.
  1287.  
  1288. Typical use:
  1289.  
  1290.     $start = $vector->Size() - 1;
  1291.     while (($start >= 0) &&
  1292.         (($min,$max) = $vector->Interval_Scan_dec($start)))
  1293.     {
  1294.         $start = $min - 2;
  1295.  
  1296.     }
  1297.  
  1298. =item *
  1299.  
  1300. C<$vector-E<gt>Bit_Off($index);>
  1301.  
  1302. Clears the bit with index "$index" in the given vector.
  1303.  
  1304. This is equivalent to removing the element "$index"
  1305. from the given set.
  1306.  
  1307. Note that if you specify a negative number for "$index"
  1308. it will be interpreted as a large positive number due
  1309. to its internal 2's complement binary representation!
  1310.  
  1311. An exception is raised if "$index" lies outside the
  1312. permitted range from "C<0>" to "C<$vector-E<gt>Size()-1>".
  1313.  
  1314. =item *
  1315.  
  1316. C<$vector-E<gt>Bit_On($index);>
  1317.  
  1318. Sets the bit with index "$index" in the given vector.
  1319.  
  1320. This is equivalent to adding the element "$index"
  1321. to the given set.
  1322.  
  1323. Note that if you specify a negative number for "$index"
  1324. it will be interpreted as a large positive number due
  1325. to its internal 2's complement binary representation!
  1326.  
  1327. An exception is raised if "$index" lies outside the
  1328. permitted range from "C<0>" to "C<$vector-E<gt>Size()-1>".
  1329.  
  1330. =item *
  1331.  
  1332. C<$vector-E<gt>bit_flip($index)>
  1333.  
  1334. Flips (i.e., complements) the bit with index "$index"
  1335. in the given vector.
  1336.  
  1337. This is equivalent to adding the element "$index"
  1338. to the given set if it is NOT contained yet and
  1339. removing it if it IS contained.
  1340.  
  1341. Also returns the NEW state of the specified bit, i.e.,
  1342. returns "0" if it is cleared (in the "off" state) or
  1343. "1" if it is set (in the "on" state).
  1344.  
  1345. In other words it returns "true" if the specified
  1346. element is contained in the given set and "false"
  1347. otherwise.
  1348.  
  1349. Note that if you specify a negative number for "$index"
  1350. it will be interpreted as a large positive number due
  1351. to its internal 2's complement binary representation!
  1352.  
  1353. An exception is raised if "$index" lies outside the
  1354. permitted range from "C<0>" to "C<$vector-E<gt>Size()-1>".
  1355.  
  1356. =item *
  1357.  
  1358. C<$vector-E<gt>bit_test($index)>
  1359.  
  1360. Returns the current state of the bit with index "$index"
  1361. in the given vector, i.e., returns "0" if it is cleared
  1362. (in the "off" state) or "1" if it is set (in the "on" state).
  1363.  
  1364. In other words it returns "true" if the specified
  1365. element is contained in the given set and "false"
  1366. otherwise.
  1367.  
  1368. Note that if you specify a negative number for "$index"
  1369. it will be interpreted as a large positive number due
  1370. to its internal 2's complement binary representation!
  1371.  
  1372. An exception is raised if "$index" lies outside the
  1373. permitted range from "C<0>" to "C<$vector-E<gt>Size()-1>".
  1374.  
  1375. =item *
  1376.  
  1377. C<$vector-E<gt>is_empty()>
  1378.  
  1379. Tests wether the given bit vector is empty, i.e., wether ALL of
  1380. its bits are cleared (in the "off" state).
  1381.  
  1382. Returns "true" ("1") if the bit vector is empty and "false" ("0")
  1383. otherwise.
  1384.  
  1385. =item *
  1386.  
  1387. C<$vector-E<gt>is_full()>
  1388.  
  1389. Tests wether the given bit vector is full, i.e., wether ALL of
  1390. its bits are set (in the "on" state).
  1391.  
  1392. Returns "true" ("1") if the bit vector is full and "false" ("0")
  1393. otherwise.
  1394.  
  1395. =item *
  1396.  
  1397. C<$vector1-E<gt>equal($vector2)>
  1398.  
  1399. Tests the two given bit vectors for equality.
  1400.  
  1401. Returns "true" ("1") if the two bit vectors are exact
  1402. copies of one another and "false" ("0") otherwise.
  1403.  
  1404. An exception is raised if the two bit vectors have
  1405. different sizes, i.e., if C<$vector1-E<gt>Size()>
  1406. C<!=> C<$vector2-E<gt>Size()>.
  1407.  
  1408. =item *
  1409.  
  1410. C<$vector1-E<gt>lexorder($vector2)>
  1411.  
  1412. Tests the lexical order of the two given bit vectors.
  1413.  
  1414. I.e., the two bit vectors are regarded as two large
  1415. (positive) numbers in binary representation which
  1416. are compared.
  1417.  
  1418. The least significant bit (LSB) of this binary number
  1419. is the bit with index "C<0>", the most significant bit
  1420. (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1421.  
  1422. Returns "true" ("1") if the first bit vector is less
  1423. than or equal to the second bit vector and "false"
  1424. ("0") otherwise.
  1425.  
  1426. An exception is raised if the two bit vectors have
  1427. different sizes, i.e., if C<$vector1-E<gt>Size()>
  1428. C<!=> C<$vector2-E<gt>Size()>.
  1429.  
  1430. =item *
  1431.  
  1432. C<$vector1-E<gt>Compare($vector2)>
  1433.  
  1434. Compares the two given bit vectors.
  1435.  
  1436. I.e., the two bit vectors are regarded as two large
  1437. (positive) numbers in binary representation which
  1438. are compared.
  1439.  
  1440. The least significant bit (LSB) of this binary number
  1441. is the bit with index "C<0>", the most significant bit
  1442. (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1443.  
  1444. Returns "-1" if the first bit vector is less than the
  1445. second bit vector, "0" if the two bit vectors are exact
  1446. copies of one another and "1" if the first bit vector
  1447. is greater than the second bit vector.
  1448.  
  1449. An exception is raised if the two bit vectors have
  1450. different sizes, i.e., if C<$vector1-E<gt>Size()>
  1451. C<!=> C<$vector2-E<gt>Size()>.
  1452.  
  1453. =item *
  1454.  
  1455. C<$vector1-E<gt>Copy($vector2);>
  1456.  
  1457. Copies the contents of bit vector "$vector2" to
  1458. bit vector "$vector1".
  1459.  
  1460. The previous contents of bit vector "$vector1"
  1461. get overwritten, i.e., are lost.
  1462.  
  1463. Both vectors must exist beforehand, i.e., this method
  1464. does not CREATE any new bit vector object!
  1465.  
  1466. An exception is raised if the two bit vectors have
  1467. different sizes, i.e., if C<$vector1-E<gt>Size()>
  1468. C<!=> C<$vector2-E<gt>Size()>.
  1469.  
  1470. =item *
  1471.  
  1472. C<$carry_out = $vector-E<gt>rotate_left();>
  1473.  
  1474.   carry             MSB           vector:           LSB
  1475.    out:
  1476.   +---+            +---+---+---+---     ---+---+---+---+
  1477.   |   |  <---+---  |   |   |   |    ...    |   |   |   |  <---+
  1478.   +---+      |     +---+---+---+---     ---+---+---+---+      |
  1479.              |                                                |
  1480.              +------------------------------------------------+
  1481.  
  1482. The least significant bit (LSB) is the bit with index "C<0>", the most
  1483. significant bit (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1484.  
  1485. =item *
  1486.  
  1487. C<$carry_out = $vector-E<gt>rotate_right();>
  1488.  
  1489.           MSB           vector:           LSB            carry
  1490.                                                           out:
  1491.          +---+---+---+---     ---+---+---+---+           +---+
  1492.   +--->  |   |   |   |    ...    |   |   |   |  ---+---> |   |
  1493.   |      +---+---+---+---     ---+---+---+---+     |     +---+
  1494.   |                                                |
  1495.   +------------------------------------------------+
  1496.  
  1497. The least significant bit (LSB) is the bit with index "C<0>", the most
  1498. significant bit (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1499.  
  1500. =item *
  1501.  
  1502. C<$carry_out = $vector-E<gt>shift_left($carry_in);>
  1503.  
  1504.   carry         MSB           vector:           LSB         carry
  1505.    out:                                                      in:
  1506.   +---+        +---+---+---+---     ---+---+---+---+        +---+
  1507.   |   |  <---  |   |   |   |    ...    |   |   |   |  <---  |   |
  1508.   +---+        +---+---+---+---     ---+---+---+---+        +---+
  1509.  
  1510. The least significant bit (LSB) is the bit with index "C<0>", the most
  1511. significant bit (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1512.  
  1513. =item *
  1514.  
  1515. C<$carry_out = $vector-E<gt>shift_right($carry_in);>
  1516.  
  1517.   carry         MSB           vector:           LSB         carry
  1518.    in:                                                       out:
  1519.   +---+        +---+---+---+---     ---+---+---+---+        +---+
  1520.   |   |  --->  |   |   |   |    ...    |   |   |   |  --->  |   |
  1521.   +---+        +---+---+---+---     ---+---+---+---+        +---+
  1522.  
  1523. The least significant bit (LSB) is the bit with index "C<0>", the most
  1524. significant bit (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1525.  
  1526. =item *
  1527.  
  1528. C<$vector-E<gt>Move_Left($bits);>
  1529.  
  1530. Shifts the given bit vector left by "$bits" bits, i.e., inserts "$bits"
  1531. new bits at the lower end (least significant bit) of the bit vector,
  1532. moving all other bits up by "$bits" places, thereby losing the "$bits"
  1533. most significant bits.
  1534.  
  1535. The inserted new bits are all cleared (set to the "off" state).
  1536.  
  1537. This method does nothing if "$bits" is equal to zero.
  1538.  
  1539. Beware that the whole bit vector is cleared WITHOUT WARNING if "$bits"
  1540. is greater than or equal to the size of the given bit vector!
  1541.  
  1542. Beware also that if you specify a negative number for "$bits", it will be
  1543. interpreted as a large positive number due to its internal 2's complement
  1544. binary representation, which will probably empty your bit vector!
  1545.  
  1546. In fact this method is equivalent to
  1547.  
  1548.   for ( $i = 0; $i < $bits; $i++ ) { $vector->shift_left(0); }
  1549.  
  1550. except that it is much more efficient (for "$bits" greater than or
  1551. equal to the number of bits in a machine word on your system) than
  1552. this straightforward approach.
  1553.  
  1554. =item *
  1555.  
  1556. C<$vector-E<gt>Move_Right($bits);>
  1557.  
  1558. Shifts the given bit vector right by "$bits" bits, i.e., deletes the
  1559. "$bits" least significant bits of the bit vector, moving all other bits
  1560. down by "$bits" places, thereby creating "$bits" new bits at the upper
  1561. end (most significant bit) of the bit vector.
  1562.  
  1563. These new bits are all cleared (set to the "off" state).
  1564.  
  1565. This method does nothing if "$bits" is equal to zero.
  1566.  
  1567. Beware that the whole bit vector is cleared WITHOUT WARNING if "$bits"
  1568. is greater than or equal to the size of the given bit vector!
  1569.  
  1570. Beware also that if you specify a negative number for "$bits", it will be
  1571. interpreted as a large positive number due to its internal 2's complement
  1572. binary representation, which will probably empty your bit vector!
  1573.  
  1574. In fact this method is equivalent to
  1575.  
  1576.   for ( $i = 0; $i < $bits; $i++ ) { $vector->shift_right(0); }
  1577.  
  1578. except that it is much more efficient (for "$bits" greater than or
  1579. equal to the number of bits in a machine word on your system) than
  1580. this straightforward approach.
  1581.  
  1582. =item *
  1583.  
  1584. C<$carry = $vector-E<gt>increment();>
  1585.  
  1586. This method is crucial for generating all possible patterns of set
  1587. and cleared bits for a given bit vector in an ordered fashion, a
  1588. feature needed in many applications to cycle through all possible
  1589. values a bit vector of the given length can assume.
  1590.  
  1591. The method increments the given bit vector as though it was a large
  1592. (positive) number in binary representation.
  1593.  
  1594. The least significant bit (LSB) of this binary number
  1595. is the bit with index "C<0>", the most significant bit
  1596. (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1597.  
  1598. This method returns "true" ("1") if a carry-over occurred, i.e.,
  1599. if the bit vector was completely filled with set bits before this
  1600. operation took place (the bit vector will contain only cleared bits
  1601. after this operation in that case) and "false" ("0") otherwise.
  1602.  
  1603. This can be used as the terminating condition in a "while" loop,
  1604. for instance.
  1605.  
  1606. =item *
  1607.  
  1608. C<$carry = $vector-E<gt>decrement();>
  1609.  
  1610. This method is crucial for generating all possible patterns of set
  1611. and cleared bits for a given bit vector in an ordered fashion, a
  1612. feature needed in many applications to cycle through all possible
  1613. values a bit vector of the given length can assume.
  1614.  
  1615. The method decrements the given bit vector as though it was a large
  1616. (positive) number in binary representation.
  1617.  
  1618. The least significant bit (LSB) of this binary number
  1619. is the bit with index "C<0>", the most significant bit
  1620. (MSB) is the bit with index "C<$vector-E<gt>Size()-1>".
  1621.  
  1622. This method returns "true" ("1") if a carry-over occurred, i.e.,
  1623. if the bit vector was completely filled with cleared bits before
  1624. this operation took place (the bit vector will contain only set bits
  1625. after this operation in that case) and "false" ("0") otherwise.
  1626.  
  1627. This can be used as the terminating condition in a "while" loop,
  1628. for instance.
  1629.  
  1630. =item *
  1631.  
  1632. C<$string = $vector-E<gt>to_String();>
  1633.  
  1634. Returns a hexadecimal string representing the given bit vector.
  1635.  
  1636. Note that this representation is quite compact, in that it only
  1637. needs twice the number of bytes needed to store the bit vector
  1638. itself, internally!
  1639.  
  1640. The rightmost hexadecimal digit in this string represents the
  1641. four least significant bits of the given bit vector (i.e., the
  1642. bits with indices "3", "2", "1" and "0").
  1643.  
  1644. The leftmost hexadecimal digit(s) in the string represent(s) the
  1645. most significant and/or unused bits - this is due to the fact
  1646. that this class uses machine words as its basic storage unit (to
  1647. increase efficiency).
  1648.  
  1649. Since a hexadecimal digit is always worth four bits, the length
  1650. of the string always corresponds to a multiple of four bits anyway.
  1651.  
  1652. To spare extra overhead, the most significant machine word is always
  1653. completely converted into hexadecimal characters - which may produce
  1654. some (innocuous) leading hexadecimal zeros at the left end of the string
  1655. representing the unused bits of that bit vector.
  1656.  
  1657. =item *
  1658.  
  1659. C<$vector-E<gt>from_string($string)>
  1660.  
  1661. Allows to read in the contents of a bit vector from a hexadecimal
  1662. string, such as returned by the method "to_String()" (described
  1663. immediately above), for instance.
  1664.  
  1665. The string is read from right to left (!), and the bits corresponding
  1666. to each hexadecimal digit are assigned to the bits in the given bit
  1667. vector in ascending order of their indices, i.e., the rightmost
  1668. hexadecimal digit is assigned to the bits with indices "0", "1", "2"
  1669. and "3", the second rightmost hexadecimal digit is assigned to the
  1670. bits with indices "4", "5", "6" and "7", and so on.
  1671.  
  1672. If the given string contains less hexadecimal digits than are needed
  1673. to completely fill the given bit vector, the remaining bits are all
  1674. cleared.
  1675.  
  1676. In other words, even if the given string does not contain enough digits
  1677. to completely fill the given bit vector, the previous contents of the
  1678. bit vector are erased completely.
  1679.  
  1680. If the given string is longer than it needs to fill the given bit vector,
  1681. the superfluous characters are simply ignored.
  1682.  
  1683. (In fact they are ignored completely - they are not even checked for
  1684. proper syntax! See also immediately below.)
  1685.  
  1686. This behaviour is intentional so that you may read in the string
  1687. representing one bit vector into another bit vector of different
  1688. size, i.e., as much of it as will fit!
  1689.  
  1690. If during the process of reading the given string any character is
  1691. encountered which is not a hexadecimal digit, an error ensues.
  1692.  
  1693. In such a case the bit vector is filled up with zeros starting at
  1694. the point of the error and the method returns "false" ("0").
  1695.  
  1696. If all goes well the method returns "true" ("1").
  1697.  
  1698. =item *
  1699.  
  1700. C<$set1-E<gt>Union($set2,$set3);>
  1701.  
  1702. This method calculates the union of "$set2" and "$set3" and stores
  1703. the result in "$set1".
  1704.  
  1705. This is usually written as "C<$set1 = $set2 u $set3>" in set theory
  1706. (where "u" is the "cup" operator).
  1707.  
  1708. (On systems where the "cup" character is unavailable this operator
  1709. is often denoted by a plus sign "+".)
  1710.  
  1711. In-place calculation is also possible, i.e., "$set1" may be identical
  1712. with "$set2" or "$set3" or both.
  1713.  
  1714. An exception is raised if the sizes of the three sets do not match.
  1715.  
  1716. =item *
  1717.  
  1718. C<$set1-E<gt>Intersection($set2,$set3);>
  1719.  
  1720. This method calculates the intersection of "$set2" and "$set3" and
  1721. stores the result in "$set1".
  1722.  
  1723. This is usually written as "C<$set1 = $set2 n $set3>" in set theory
  1724. (where "n" is the "cap" operator).
  1725.  
  1726. (On systems where the "cap" character is unavailable this operator
  1727. is often denoted by an asterisk "*".)
  1728.  
  1729. In-place calculation is also possible, i.e., "$set1" may be identical
  1730. with "$set2" or "$set3" or both.
  1731.  
  1732. An exception is raised if the sizes of the three sets do not match.
  1733.  
  1734. =item *
  1735.  
  1736. C<$set1-E<gt>Difference($set2,$set3);>
  1737.  
  1738. This method calculates the difference of "$set2" less "$set3" and
  1739. stores the result in "$set1".
  1740.  
  1741. This is usually written as "C<$set1 = $set2 \ $set3>" in set theory
  1742. (where "\" is the "less" operator).
  1743.  
  1744. In-place calculation is also possible, i.e., "$set1" may be identical
  1745. with "$set2" or "$set3" or both.
  1746.  
  1747. An exception is raised if the sizes of the three sets do not match.
  1748.  
  1749. =item *
  1750.  
  1751. C<$set1-E<gt>ExclusiveOr($set2,$set3);>
  1752.  
  1753. This method calculates the symmetric difference of "$set2" and "$set3"
  1754. and stores the result in "$set1".
  1755.  
  1756. This can be written as "C<($vec2 u $vec3) \ ($vec2 n $vec3)>" in set
  1757. theory (the union of the two sets less their intersection).
  1758.  
  1759. When sets are implemented as bit vectors then the above formula is
  1760. equivalent to the exclusive-or between corresponding bits of the two
  1761. bit vectors (hence the name of this method).
  1762.  
  1763. Note that this method is also much more efficient than evaluating the
  1764. above formula explicitly since it uses a built-in machine language
  1765. instruction internally.
  1766.  
  1767. In-place calculation is also possible, i.e., "$set1" may be identical
  1768. with "$set2" or "$set3" or both.
  1769.  
  1770. An exception is raised if the sizes of the three sets do not match.
  1771.  
  1772. =item *
  1773.  
  1774. C<$set1-E<gt>Complement($set2);>
  1775.  
  1776. This method calculates the complement of "$set2" and stores the result
  1777. in "$set1".
  1778.  
  1779. In-place calculation is also possible, i.e., "$set1" may be identical
  1780. with "$set2".
  1781.  
  1782. An exception is raised if the sizes of the two sets do not match.
  1783.  
  1784. =item *
  1785.  
  1786. C<$set1-E<gt>subset($set2)>
  1787.  
  1788. Returns "true" ("1") if "$set1" is a subset of "$set2"
  1789. (i.e., completely contained in "$set2") and "false" ("0")
  1790. otherwise.
  1791.  
  1792. Note that by definition, if two sets are identical they are
  1793. also subsets (and also supersets) of each other.
  1794.  
  1795. An exception is raised if the sizes of the two sets do not match.
  1796.  
  1797. =item *
  1798.  
  1799. C<$norm = $set-E<gt>Norm();>
  1800.  
  1801. Returns the norm (number of bits which are set) of the given vector.
  1802.  
  1803. This is equivalent to the number of elements contained in the given
  1804. set.
  1805.  
  1806. =item *
  1807.  
  1808. C<$min = $set-E<gt>Min();>
  1809.  
  1810. Returns the minimum of the given set.
  1811.  
  1812. If the set is empty, plus infinity (represented by the constant
  1813. "MAX_LONG" on your system) is returned.
  1814.  
  1815. =item *
  1816.  
  1817. C<$max = $set-E<gt>Max();>
  1818.  
  1819. Returns the maximum of the given set.
  1820.  
  1821. If the set is empty, minus infinity (represented by the constant
  1822. "MIN_LONG" on your system) is returned.
  1823.  
  1824. =item *
  1825.  
  1826. C<$m1-E<gt>Multiplication($r1,$c1,$m2,$r2,$c2,$m3,$r3,$c3,);>
  1827.  
  1828. This method multiplies two boolean matrices (stored as bit vectors)
  1829. "$m2" and "$m3" and stores the result in matrix "$m1".
  1830.  
  1831. An exception is raised if the product of the number of rows and
  1832. columns of any of the three matrices differs from the size of
  1833. the corresponding bit vector.
  1834.  
  1835. An exception is also raised if the numbers of rows and columns
  1836. of the three matrices do not harmonize in the required manner:
  1837.  
  1838.   rows1 == rows2
  1839.   cols1 == cols3
  1840.   cols2 == rows3
  1841.  
  1842. This method is used by the "Math::MatrixBool" application class
  1843. (see also L<Math::MatrixBool(3)>).
  1844.  
  1845. =item *
  1846.  
  1847. C<$matrix-E<gt>Closure($rows,$cols);>
  1848.  
  1849. This method calculates the reflexive transitive closure of the
  1850. given boolean matrix (stored as a bit vector) using Kleene's
  1851. algoritm.
  1852.  
  1853. (See L<Math::Kleene(3)> for a brief introduction into the
  1854. theory behind Kleene's algorithm.)
  1855.  
  1856. The reflexive transitive closure answers the question wether
  1857. a path exists between any two vortices of a graph whose edges
  1858. are given as a matrix:
  1859.  
  1860. If a (directed) edge exists going from vortex "i" to vortex "j",
  1861. then the element in the matrix with coordinates (i,j) is set to
  1862. "1" (otherwise it remains set to "0").
  1863.  
  1864. If the edges are undirected the resulting matrix is symmetric,
  1865. i.e., elements (i,j) and (j,i) always contain the same value.
  1866.  
  1867. The matrix representing the edges of the graph only answers the
  1868. question wether an EDGE (!) exists between any two vortices of
  1869. the graph or not, whereas the reflexive transitive closure
  1870. answers the question wether a PATH (a series of adjacent edges)
  1871. exists between any two vortices of the graph!
  1872.  
  1873. Note that the contents of the given matrix are modified by
  1874. this method, so make a copy of the initial matrix in time
  1875. if you are going to need it again later!
  1876.  
  1877. An exception is raised if the given matrix is not quadratic,
  1878. i.e., if the number of rows and columns of the given matrix
  1879. is not identical.
  1880.  
  1881. An exception is also raised if the product of the number of
  1882. rows and columns of the given matrix differs from the size
  1883. of its underlying bit vector.
  1884.  
  1885. This method is used by the "Math::MatrixBool" application class
  1886. (see also L<Math::MatrixBool(3)>).
  1887.  
  1888. =back
  1889.  
  1890. =head2 METHODS IMPLEMENTED IN PERL
  1891.  
  1892. =over 2
  1893.  
  1894. =item *
  1895.  
  1896. C<$other_vector = $some_vector-E<gt>Shadow();>
  1897.  
  1898. Creates a NEW bit vector of the SAME SIZE as "$some_vector"
  1899. which is EMPTY.
  1900.  
  1901. Just like a shadow that has the same shape as the object it
  1902. originates from, but is flat and has no volume, i.e., contains
  1903. nothing.
  1904.  
  1905. =item *
  1906.  
  1907. C<$twin_vector = $some_vector-E<gt>Clone();>
  1908.  
  1909. Creates a NEW bit vector of the SAME SIZE as "$some_vector"
  1910. which is an EXACT COPY of "$some_vector".
  1911.  
  1912. =item *
  1913.  
  1914. C<$vector = Bit::Vector-E<gt>new_from_String($string);>
  1915.  
  1916. Creates a new bit vector of the size C<4 * length($string)>
  1917. and tries to fill it with the contents of "$string" which
  1918. must consist entirely of hexadecimal characters.
  1919.  
  1920. Example:
  1921.  
  1922.   $vector = Bit::Vector->new_from_String("20208828828208A20A08A28AC");
  1923.  
  1924. (Fills "$vector" with all prime numbers below 100.)
  1925.  
  1926. Hexadecimal characters "A" through "F" may be in lower or upper case
  1927. indiscriminately.
  1928.  
  1929. An exception is raised if the string contains other than hexadecimal
  1930. characters.
  1931.  
  1932. An exception is also raised if the string is empty because bit vectors
  1933. of zero elements (length zero) are not permitted in this class.
  1934.  
  1935. Finally, an exception is also raised if the necessary memory for the
  1936. bit vector cannot be allocated.
  1937.  
  1938. =item *
  1939.  
  1940. C<$string = $vector-E<gt>to_ASCII();>
  1941.  
  1942. Converts the given bit vector or set into an enumeration of single
  1943. indices and ranges of indices ("newsrc" style), representing the
  1944. bits that are set (i.e., in the "on" state) in the bit vector.
  1945.  
  1946. Example:
  1947.  
  1948.   $vector = Bit::Vector->new(20);
  1949.   $vector->Bit_On(2);
  1950.   $vector->Bit_On(3);
  1951.   $vector->Bit_On(11);
  1952.   $vector->Interval_Fill(5,7);
  1953.   $vector->Interval_Fill(13,19);
  1954.   print $vector->to_ASCII(), "\n";
  1955.  
  1956. which prints "2,3,5-7,11,13-19".
  1957.  
  1958. If the given bit vector is empty the resulting string will
  1959. also be empty.
  1960.  
  1961. =item *
  1962.  
  1963. C<$vector-E<gt>from_ASCII($string);>
  1964.  
  1965. First empties the given vector and then tries to set the
  1966. bits and ranges of bits specified in the given string.
  1967.  
  1968. The string "$string" must contain positive integers or
  1969. ranges (two positive integers separated by a dash "-")
  1970. separated by commas.
  1971.  
  1972. All other characters are disallowed (including white space).
  1973.  
  1974. An exception will be raised if the string does not obey
  1975. this syntax.
  1976.  
  1977. In each range the first integer must always be less than
  1978. or equal to the second one, otherwise an exception is raised.
  1979.  
  1980. An exception is also raised if any of the integers exceeds
  1981. the range of permitted indices in the given string, i.e., if
  1982. any integer is greater than or equal to C<$vector-E<gt>Size()>.
  1983.  
  1984. Example:
  1985.  
  1986.   eval { $vector->from_ASCII("2,3,5-7,11,13-19"); };
  1987.  
  1988. Note that the order of the indices and ranges is irrelevant,
  1989. i.e.,
  1990.  
  1991.   eval { $vector->from_ASCII("11,5-7,3,13-19,2"); };
  1992.  
  1993. results in the same vector as in the example above.
  1994.  
  1995. Ranges and indices may also overlap.
  1996.  
  1997. This is because each (single) index in the string is passed
  1998. to the method "Bit_On()" and each range to the method
  1999. "Interval_Fill()" internally.
  2000.  
  2001. So the resulting vector (or set) is just the union of all
  2002. the specified elements and ranges.
  2003.  
  2004. =back
  2005.  
  2006. =head2 OVERLOADED OPERATORS
  2007.  
  2008. =over 2
  2009.  
  2010. =item *
  2011.  
  2012. Emptyness
  2013.  
  2014. Note that the method for determining emptyness is quite efficient:
  2015.  
  2016. The method stops searching the given bit vector as soon as it finds
  2017. the first non-zero machine word.
  2018.  
  2019. =item *
  2020.  
  2021. Equality
  2022.  
  2023. The method for determining equality is also quite efficient:
  2024.  
  2025. It stops at the first differing machine word it finds.
  2026.  
  2027. =item *
  2028.  
  2029. Lexical Comparison
  2030.  
  2031. Using the overloaded operator "cmp" to compare two bit vectors as in
  2032. "C<$vector1 cmp $vector2>" is essentially the same as comparing the
  2033. two corresponding hexadecimal strings returned by the "to_String()"
  2034. method, i.e., "C<$vector1-E<gt>to_String() cmp $vector2-E<gt>to_String()>".
  2035.  
  2036. The result is exactly the same (provided that both bit vectors have
  2037. the same size!), but using the overloaded operator "cmp" is much more
  2038. efficient since the additional overhead of converting both bit vectors
  2039. into strings is avoided.
  2040.  
  2041. Moreover, with the overloaded operator "cmp", the two bit vectors
  2042. are compared one machine word (usually 32 or 64 bits) at a time,
  2043. which is much faster than comparing one hexadecimal character
  2044. (4 bits worth!) at a time in a string comparison.
  2045.  
  2046. This comparison ends as soon as two differing words are found, i.e.,
  2047. in many cases the operator doesn't even need to look at the entire
  2048. bit vector!
  2049.  
  2050. Again, since the operator looks at more bits at a time, the search
  2051. ends much earlier than in a string comparison.
  2052.  
  2053. =item *
  2054.  
  2055. Move Left
  2056.  
  2057. In its first form, C<$vector1 = $vector2 E<lt>E<lt> $bits;>, creates
  2058. a new vector of the same size as "$vector2", copies the contents of
  2059. "$vector2" to it, then shifts this new vector left by the indicated
  2060. number of bits and finally returns a reference to this new vector.
  2061.  
  2062. Note that an exception will be raised if you swap the two arguments
  2063. of this operator.
  2064.  
  2065. In its second form, C<$vector E<lt>E<lt>= $bits;>, shifts the given
  2066. vector "$vector" left by the indicated number of bits.
  2067.  
  2068. =item *
  2069.  
  2070. Move Right
  2071.  
  2072. In its first form, C<$vector1 = $vector2 E<gt>E<gt> $bits;>, creates
  2073. a new vector of the same size as "$vector2", copies the contents of
  2074. "$vector2" to it, then shifts this new vector right by the indicated
  2075. number of bits and finally returns a reference to this new vector.
  2076.  
  2077. Note that an exception will be raised if you swap the two arguments
  2078. of this operator.
  2079.  
  2080. In its second form, C<$vector E<gt>E<gt>= $bits;>, shifts the given
  2081. vector "$vector" right by the indicated number of bits.
  2082.  
  2083. =item *
  2084.  
  2085. String Conversion
  2086.  
  2087. Currently, converting a bit vector into a string using the overloaded
  2088. operator C<""> is performed using the method "to_ASCII()" internally,
  2089. which is probably the preferred behaviour.
  2090.  
  2091. If you think that this operator should rather convert any given bit
  2092. vector into a hexadecimal string using the method "to_String()", then
  2093. you should edit the file "Vector.pm" in this distribution as follows:
  2094.  
  2095. Locate the method "sub _string" and change the line
  2096.  
  2097.   return( $object->to_ASCII() );
  2098.  
  2099. to
  2100.  
  2101.   return( $object->to_String() );
  2102.  
  2103. =item *
  2104.  
  2105. Union
  2106.  
  2107. Since there is no "cup" character in the ASCII alphabet, the plus sign "+"
  2108. is used here to denote the union operator from set theory.
  2109.  
  2110. The pipe symbol (or "vertical bar") "|" may be used as an alias for the
  2111. plus sign "+".
  2112.  
  2113. =item *
  2114.  
  2115. Intersection
  2116.  
  2117. Since there is no "cap" character in the ASCII alphabet, the asterisk "*"
  2118. is used here to denote the intersection operator from set theory.
  2119.  
  2120. The ampersand "&" may be used as an alias for the asterisk "*".
  2121.  
  2122. =item *
  2123.  
  2124. Difference
  2125.  
  2126. Since the backslash "\" is not an (overloadable) operator in Perl
  2127. (and a very special character anyway) the minus sign "-" is used
  2128. here to denote the "less" operator from set theory.
  2129.  
  2130. =item *
  2131.  
  2132. ExclusiveOr
  2133.  
  2134. Since there is no widely accepted symbol to denote the symmetric
  2135. difference in set theory (at least not to my knowledge - unless it
  2136. is the dotted minus sign, which alas is also a character unavailable
  2137. in the ASCII alphabet), the caret "^" (which is the "exclusive-or"
  2138. operator anyway) is simply used here to express the symmetric
  2139. difference of two sets.
  2140.  
  2141. =item *
  2142.  
  2143. Complement
  2144.  
  2145. The tilde "~" as well as the unary minus "-" are used here
  2146. (interchangeably!) to denote the complement of a set.
  2147.  
  2148. =item *
  2149.  
  2150. Subset Relationship
  2151.  
  2152. Since there is no "contained in or equal" sign in the ASCII alphabet,
  2153. the usual operator "<=" is used instead to denote subset relationship.
  2154.  
  2155. =item *
  2156.  
  2157. True Subset Relationship
  2158.  
  2159. Since there is no "contained in" sign in the ASCII alphabet, the usual
  2160. operator "<" is used instead to denote (true) subset relationship.
  2161.  
  2162. =item *
  2163.  
  2164. Superset Relationship
  2165.  
  2166. Since there is no "superset of or equal" sign in the ASCII alphabet,
  2167. the usual operator ">=" is used instead to denote superset relationship.
  2168.  
  2169. =item *
  2170.  
  2171. True Superset Relationship
  2172.  
  2173. Since there is no "superset of" sign in the ASCII alphabet, the usual
  2174. operator ">" is used instead to denote (true) superset relationship.
  2175.  
  2176. =item *
  2177.  
  2178. Norm
  2179.  
  2180. The function "abs()" can be used to return the number of elements in
  2181. a given set.
  2182.  
  2183. =back
  2184.  
  2185. =head1 DESCRIPTION
  2186.  
  2187. This class allows you to create bit vectors and sets of arbitrary size
  2188. (only limited by the size of a machine word and available memory on your
  2189. system) with indices (= elements) in the range from zero to some positive
  2190. integer, to dynamically change the size of such bit vectors or sets and to
  2191. perform a broad range of basic operations on them, like
  2192.  
  2193. =over 4
  2194.  
  2195. =item -
  2196.  
  2197. adding or removing elements (setting and clearing single bits),
  2198.  
  2199. =item -
  2200.  
  2201. testing the presence of a certain element (testing a single bit),
  2202.  
  2203. =item -
  2204.  
  2205. setting or clearing contiguous ranges of bits,
  2206.  
  2207. =item -
  2208.  
  2209. detecting contiguous ranges of set bits,
  2210.  
  2211. =item -
  2212.  
  2213. copying bit vectors,
  2214.  
  2215. =item -
  2216.  
  2217. converting a bit vector into either a compact (hexadecimal) or a
  2218. human-readable string representation (allowing you to store bit
  2219. vectors in a file, for instance),
  2220.  
  2221. =item -
  2222.  
  2223. reading in the contents of a bit vector from a string,
  2224.  
  2225. =item -
  2226.  
  2227. comparing two bit vectors for equality and lexical order,
  2228.  
  2229. =item -
  2230.  
  2231. performing bitwise shift and rotation operations,
  2232.  
  2233. =item -
  2234.  
  2235. computing the union, intersection, difference, symmetric difference
  2236. or complement of sets,
  2237.  
  2238. =item -
  2239.  
  2240. testing two sets for equality or inclusion (subset relationship),
  2241.  
  2242. =item -
  2243.  
  2244. computing the minimum, the maximum and the norm (number of elements)
  2245. of a set,
  2246.  
  2247. =back
  2248.  
  2249. and more.
  2250.  
  2251. Note also that it is very easy to implement sets of arbitrary intervals of
  2252. integers using this module (negative indices are no obstacle), despite the
  2253. fact that only intervals of positive integers (from zero to some positive
  2254. integer) are supported directly.
  2255.  
  2256. Please refer to the "Set::IntegerRange" module (also contained in this
  2257. distribution) and L<Set::IntegerRange(3)> to see how this can be done!
  2258.  
  2259. The "Bit::Vector" module is mainly intended for mathematical or algorithmical
  2260. computations. There are also a number of efficient algorithms that rely on
  2261. sets (and bit vectors).
  2262.  
  2263. An example of such an efficient algorithm (which uses a different
  2264. representation for sets, however, not bit vectors) is Kruskal's
  2265. algorithm for minimal spanning trees in graphs.
  2266.  
  2267. (See the module "Graph::Kruskal" and L<Graph::Kruskal(3)> in this
  2268. distribution.)
  2269.  
  2270. Another famous algorithm using bit vectors is the "Sieve of Erathostenes"
  2271. for calculating prime numbers, which is included here as a demo program
  2272. (see the file "primes.pl" in this distribution).
  2273.  
  2274. An important field of application is the computation of "first", "follow"
  2275. and "look-ahead" character sets for the construction of LL, SLR, LR and LALR
  2276. parsers for compilers (or a compiler-compiler, like "yacc", for instance).
  2277.  
  2278. (That's what the C library in this package was initially written for.)
  2279.  
  2280. (See Aho, Hopcroft, Ullman, "The Design and Analysis of Computer Algorithms"
  2281. for an excellent book on efficient algorithms and the famous "Dragon Book"
  2282. on how to build compilers by Aho, Sethi, Ullman.)
  2283.  
  2284. Therefore, this module is primarily designed for efficiency, which is the
  2285. reason why most of its methods are implemented in C.
  2286.  
  2287. To increase execution speed, the module doesn't use bytes as its basic storage
  2288. unit, it rather uses machine words, assuming that a machine word is the most
  2289. efficiently handled size of all scalar types on any machine (that's what the
  2290. ANSI C standard proposes and assumes anyway).
  2291.  
  2292. In order to achieve this, it automatically determines the number of bits
  2293. in a machine word on your system and then adjusts its internal configuration
  2294. constants accordingly.
  2295.  
  2296. The greater the size of this basic storage unit, the better the complexity
  2297. (= execution speed) of the methods in this module (but also the greater the
  2298. average waste of unused bits in the last word).
  2299.  
  2300. Note that the C library of this package ("BitVector.c") is designed in such
  2301. a way that it can be used independently from Perl and this Perl extension
  2302. module. (!)
  2303.  
  2304. For this, you can use the file "BitVector.o" exactly as it is produced when
  2305. building this module! It contains no references to Perl, and it doesn't need
  2306. any Perl header files in order to compile. (It only needs "Definitions.h" and
  2307. some system header files.)
  2308.  
  2309. Note however that this C library does not perform any bounds checking
  2310. whatsoever! (This is your application's duty!)
  2311.  
  2312. (See the respective explanation in the file "BitVector.c" for more details
  2313. and the file "Vector.xs" for an example of how this can be done!)
  2314.  
  2315. In this module, all bounds and type checking (which should be absolutely
  2316. fool-proof, BTW!) is done in the XSUB routines (in C).
  2317.  
  2318. For more details about the modules in this distribution, please refer to
  2319. their respective man pages!
  2320.  
  2321. =head1 SEE ALSO
  2322.  
  2323. Set::IntegerFast(3), Set::IntegerRange(3), Math::MatrixBool(3),
  2324. Math::MatrixReal(3), DFA::Kleene(3), Math::Kleene(3), Graph::Kruskal(3).
  2325.  
  2326. perl(1), perlsub(1), perlmod(1), perlref(1), perlobj(1), perlbot(1),
  2327. perltoot(1), perlxs(1), perlxstut(1), perlguts(1), overload(3).
  2328.  
  2329. =head1 VERSION
  2330.  
  2331. This man page documents "Bit::Vector" version 4.2.
  2332.  
  2333. =head1 AUTHOR
  2334.  
  2335. Steffen Beyer <sb@sdm.de>.
  2336.  
  2337. =head1 COPYRIGHT
  2338.  
  2339. Copyright (c) 1995, 1996, 1997 by Steffen Beyer. All rights reserved.
  2340.  
  2341. =head1 LICENSE
  2342.  
  2343. This package is free software; you can redistribute it and/or modify
  2344. it under the same terms as Perl itself.
  2345.  
  2346.